package com.example.backend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.backend.entity.UserCard;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface UserCardMapper extends BaseMapper<UserCard> {
    //从用户表和连接表获取
    @Select("SELECT users_card_link.*, card_group.category, card_group.card_id as card_order," +
            "card_group.image as image_src FROM users_card_link,card_group " +
            "WHERE users_card_link.card_id=card_group.id AND users_card_link.user_id=#{id}")
    List<UserCard> getUserCardById(String id);
    //获取全部卡片
    @Select("SELECT card_group.id as id ,card_group.category, card_group.card_id as card_order,card_group.image as image_src FROM" +
            " card_group ")
    List<UserCard> getUserCardAll(String id);
    //获取单个映射关系表
    @Select("SELECT users_card_link.* FROM users_card_link WHERE users_card_link.id=#{id}")
    UserCard getSingleUserCardById(int id);
    //更新用户与卡片映射表
    @Update("UPDATE users_card_link SET users_card_link.collect=#{data} WHERE users_card_link.id=#{id}")
    void updateUsersCard(int data,int id);
    //更新
    @Update("UPDATE users_data SET users_data.time=users_data.time-1 WHERE users_data.open_id=#{openId}")
    void updateUserTime(String openId);
}
